// components/camp-activity/camp-activity.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    campActivityStatus: {
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    campActivityStatus: false,
    addList: [], //整体数据
    campId: "",
    scenicId: "", //景点id
    imageUrl: "",
    introduce: '',
    fileList: [],
    activityName: "",
    memberPrice: "",
    originalPrice: "",
  },
  lifetimes: {
    ready() {

    }
  },
  /**
   * 组件的方法列表
   */
  methods: {

    //重置数据
    resetData() {
      this.setData({
        // conditionList: result
        activityName: "",
        memberPrice: "",
        originalPrice: "",
        introduce: "",
      })
    },
    //添加虚拟数据
    addData(e) {
      const object = {
        activityName: e.detail.value.activityName,
        memberPrice: Number(e.detail.value?.memberPrice),
        originalPrice: Number(e.detail.value.originalPrice),
        introduce: this.data.introduce,
      }
      console.log(object);
      var isEmpty = true;
      Object.keys(object).forEach(function (x) {
        if (object[x] === null || object[x] === "") {
          isEmpty = false;
        }
      });
      if (isEmpty) {
        this.data.addList.push({
          activityName: e.detail.value.activityName,
          memberPrice: Number(e.detail.value?.memberPrice),
          originalPrice: Number(e.detail.value.originalPrice),
          introduce: this.data.introduce,
        })
        this.resetData();
        this.onClose();
        this.triggerEvent("sendData", this.data.addList)
      } else {
        wx.showToast({
          title: "信息未填写完整",
          icon: "error",
          duration: 1500
        })
      }

      // console.log(instance.globalData.campData)
      console.log(this.data.addList);
    },
    onClose() {
      this.resetData()
      this.setData({
        campActivityStatus: false
      })
    },

    // 绑定营地介绍
    changeIntroduce(e) {
      this.setData({
        introduce: e.detail.value
      })
    },
  }
})